<template>
    <div class="goods-list">
        <router-link class="goods-item" to="/home/goodsinfo" tag="div">
            <img src="../../images/g1.jpg">
            <h1 class="title">
                小米8 青春版
                潮流镜面渐变色，2400万自拍旗舰</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥1399</span>
                    <span class="old">￥1499</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩60件</span>
                </p>
        </div>
        </router-link>
        <div class="goods-item" @click="getDetail">
            <img src="../../images/g2.jpg">
            <h1 class="title">
                小米8
                全球首款双频GPS，骁龙845</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥2499</span>
                    <span class="old">￥2699</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩600件</span>
                </p>
            </div>
        </div>
        <div class="goods-item">
            <img src="../../images/g3.jpg">
            <h1 class="title">
                红米6
                小屏高性能的双摄手机</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥699</span>
                    <span class="old">￥799</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩65件</span>
                </p>
            </div>
        </div>
        <div class="goods-item">
            <img src="../../images/g4.jpg">
            <h1 class="title">
                黑鲨游戏手机 Helo
                双液冷，更能打</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥3199</span>
                    <span class="old">￥3299</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩700件</span>
                </p>
            </div>
        </div>
        <div class="goods-item">
            <img src="../../images/g5.jpg">
            <h1 class="title">
                小米MIX 3
                磁动力滑盖全面屏</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥3299</span>
                    <span class="old">￥3299</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩500件</span>
                </p>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{}
    },
    methods: {
        getDetail(){
            //使用JS新式进行路由导航
            //注意，一定要区分this.$route和this.$router这两个对象；
            //其中，this.$route是路由参数对象，所有路由中的参数，params，query都是属于它
            //this.$router是路由导航对象，用它可以方便使用js代码，实现路由跳转

            //1.最简单的方式
            // this.$router.push('/home/goodsinfo')
            //2.传递对象
            // this.$router.push({ path:/home/goodsinfo })
            //3.传递命名的路由
            this.$router.push({ name: 'goodsinfo'})
        }
    }
};
</script>

<style lang="scss" scoped>
.goods-list {
  padding: 7px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .goods-item {
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    margin: 4px 0;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 293px;
    img {
      width: 100%;
    }
    .title {
      font-size: 14px;
    }
    .info {
      background: #eee;
      p {
        margin: 0;
        padding: 5px;
      }
      .price {
        .now {
          color: red;
          font-weight: bold;
          font-size: 16px;
        }
        .old {
          text-decoration: line-through;
          font-size: 12px;
          margin-left: 10px;
        }
      }
      .sell {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
      }
    }
  }
}
</style>


